#include <myhead.h>
int main(int argc, const char *argv[])
{
	//1、创建套接字
	int S=socket(AF_INET,SOCK_DGRAM,0);
	if(-1==S){perror("创建套接字失败\n");return -1;}
	//2、绑定服务器IP和port
	struct sockaddr_in addr={0};
	addr.sin_family=AF_INET;
	addr.sin_port=htons(12354);
	addr.sin_addr.s_addr=inet_addr("127.0.0.1");
	if(bind(S,(const struct sockaddr*)&addr,sizeof(addr))==-1){perror("绑定失败\n");return -1;}
	while(1)
	{
		char buf[128]={0};
		struct sockaddr_in addt={0};
		int len=sizeof(addt);
		printf("等待消息\n");
		int res = recvfrom(S,buf,128,0,(struct sockaddr*)&addt,&len);
		printf("res = %d",res);
		printf("接收客户端消息为%s    \n",buf);
		sendto(S,buf,strlen(buf),0,(const struct sockaddr*)&addt,len);
		//printf("接收客户端%s消息为%s\n",inet_ntoa(addt.sin_addr.s_addr),buf);
	}
	return 0;
}
